#include <iostream>
#include <sys/types.h>
#include <unistd.h>
#include "common.h"

using namespace std;

int main()
{
    // 客户端打开共享内存
    key_t key = getKey();
    int shmid = getShm(key, gsize);

    cout << "client key: " << toHEX(key) << endl;
    cout << "client shmid: " << shmid << endl;

    char *start = (char *)shmat(shmid, NULL, 0);    //关联
    if ((void *)start == (void *)-1)
    {
        cerr << "shmat fail!"
             << "errno: " << errno << " | " << strerror(errno) << endl;
        exit(1);
    }

    // 挂接成功后，睡三秒就结束
    printf("start: %p\n", start);
    sleep(3);

    shmdt(start);   //去关联
    return 0;
}